package com.cays.myresearch.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.cays.myresearch.R;
import com.cays.myresearch.entity.Projects;

import java.util.List;

public class ProjectsAdapter extends RecyclerView.Adapter<ProjectsAdapter.ViewHolder>{
    private List<Projects> ProjectsList;

    public ProjectsAdapter(List<Projects> ProjectsList) {
        this.ProjectsList = ProjectsList;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from (parent.getContext ()).inflate (R.layout.project_list_item,parent,false);
        ViewHolder holder=new ViewHolder (view);
        return holder;
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {
        Projects Projects=ProjectsList.get (position);
        holder.title.setText (Projects.getTitle ());
        holder.instruction.setText (Projects.getInstruction ());
        holder.company.setText (Projects.getCompany ());
        holder.time.setText (Projects.getTime ());
        holder.type.setText (Projects.getType ());
        holder.request.setText (Projects.getRequestor ());
        holder.location.setText (Projects.getLocation ());
        holder.status.setText (Projects.getStatus ());
        if (listener!=null){
            holder.itemView.setOnClickListener (new View.OnClickListener () {
                @Override
                public void onClick(View view) {
                    listener.onProjectsClick (holder.itemView,position);
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return ProjectsList.size ();
    }

    static class ViewHolder extends RecyclerView.ViewHolder{
        TextView title,instruction,type,time,status,request,location,company;
        public ViewHolder(View itemView) {
            super (itemView);
            title=(TextView)itemView.findViewById (R.id.project_title);
            instruction=(TextView)itemView.findViewById (R.id.project_instruction);
            type=(TextView)itemView.findViewById (R.id.project_type);
            time=(TextView)itemView.findViewById (R.id.project_time);
            status=(TextView)itemView.findViewById (R.id.project_status);
            company=(TextView)itemView.findViewById (R.id.project_company);
            location=(TextView)itemView.findViewById (R.id.project_location);
            request=(TextView)itemView.findViewById (R.id.project_request);
        }
    }
    public interface ProjectsClickListener{
        public void onProjectsClick(View item, int position);
    }
    private ProjectsClickListener listener;
    public void setProjectsClickListenerListener(ProjectsClickListener listener){
        this.listener=listener;
    }
}
